package com.yyfax.ph.personal.authority.phonechange;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Title: ChangeNewPhoneModel Description: Company: YYLending(YouJingPuHui)
 *
 * @author XiongYuFeng
 *         date 2016年5月10日 下午5:34:08
 */
public class ChangeNewPhoneModel extends Model {
	private static final String TAG = ChangeNewPhoneModel.class.getSimpleName();

	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.checkVerifyCode(token, (ChangePhoneNumParams) params);
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		ChangePhoneNumResult changePhoneNumResult = cast(obj);
		EventAgent.post(changePhoneNumResult);
	}

	private interface Service {
		@POST("sys/user/modifyPhone")
		Observable<ChangePhoneNumResult> checkVerifyCode(@Header("token") String token, @Body ChangePhoneNumParams params);
	}

	public static class ChangePhoneNumParams {
		// 新手机号（RSA加密）
		public String phone;
		// 老手机号（RSA加密）
		public String loginName;
		// 新手机验证码
		public String verifyCode;
		//旧手机校验ID
		public String verifyId;
		//极光id
		String regId = YJPH.getInstance().getPreferenceManager().getJPushRegId();
	}


	public static class SingleContentBean {
		public String code;
	}

	public static class ChangePhoneNumResult extends BaseResultEntity<SingleContentBean> {
	}
}
